<?php 
@header("Content-Type:text/html;charset=utf-8");
@include_once("conn.php");
@include_once("common.php");
if(!(isset($_GET["goodsImg"])&&isset($_GET["goodsName"])&&isset($_GET["goodsPrice"])&&isset($_GET["num"])&&isset($_GET["userName"])&&isset($_GET["goodsId"]))){
    paramsErr();
}

$goodsImg=$_GET["goodsImg"];
$goodsName=$_GET["goodsName"];
$goodsPrice=$_GET["goodsPrice"];
$num=$_GET["num"];
$userName=$_GET["userName"];
$goodsId=$_GET["goodsId"];

$sql="select * from `shoppingcart` where userName='$userName' and goodsId='$goodsId'";
$result=mysqli_query($conn,$sql);
$item = mysqli_fetch_assoc($result);
$obj = array();
if($item){
    $sum=$item["num"];
    $id=$item["id"];
    $sumone=$num+$sum;
    $sqlone= "update `shoppingcart` set num = '$sumone'  where id= $id ";
    $arr=mysqli_query($conn,$sqlone);

    if($arr){
        $obj["status"] = true;
        $obj["msg"] = "添加成功";
    }else{
        $obj["status"] = false;
            $obj["msg"] = "sql语句有误";
            $obj["sql"] = $sqlone;
    }
 
}else{
    $sqltwo="insert into `shoppingcart`(goodsImg,goodsName,goodsPrice,num,userName,goodsId) values('$goodsImg','$goodsName','$goodsPrice','$num','$userName','$goodsId')";

    $result1=mysqli_query($conn,$sqltwo);
    
        if($result1){ // 判断sql执行的结果(增删改)
       
            $obj["status"] = true;
            $obj["msg"] = "添加成功";
    
            
        }else{
            $obj["status"] = false;
            $obj["msg"] = "sql语句有误";
            $obj["sql"] = $sql;
        } 
}
    echo json_encode($obj);
?>